package cml;

import java.util.Enumeration;
import java.util.Hashtable;

public final class Lexicon {
	
	private static Hashtable<String, TokenType> reservedWords;
	
	static {
		
		reservedWords = new Hashtable<String, TokenType>();
		reservedWords.put("si", TokenType.IF);
		reservedWords.put("sino", TokenType.ELSE);
		reservedWords.put("para", TokenType.FOR);
		reservedWords.put("mientras", TokenType.WHILE);
		reservedWords.put("regresa", TokenType.RETURN);
		reservedWords.put("vacio", TokenType.VOID);
		reservedWords.put("entero", TokenType.INT);
		reservedWords.put("decimal", TokenType.DEC);
		reservedWords.put("booleano", TokenType.BOOLEAN);
		reservedWords.put("texto", TokenType.TEXT);		
	}
	
	private static Hashtable<String, TokenType> literals;
	
	static {
		
		literals = new Hashtable<String, TokenType>();
		literals.put("verdadero", TokenType.TRUE);
		literals.put("falso", TokenType.FALSE);
	}
	
	public static TokenType isReserved(String s) {
		
		return reservedWords.get(s);
	}
	
	public static TokenType isLiteral(String s) {
		
		return literals.get(s);
	}
	
	public static String getTokenString(TokenType t) {
		
		String ts = null;
		Enumeration<String> keys = reservedWords.keys();
		
		while(keys.hasMoreElements()) {
			
			String key = keys.nextElement();
			
			if(reservedWords.get(key).equals(t))
				ts = key;
		}
			
		return ts;
	}
}
